<!-- 订单管理页面 -->
<template>
	<view>
		<!-- tab及页面 -->
		<view class="tab-page">
			<view class="tab">
				<u-tabs :list="tabList" :is-scroll="false" :current="current" bar-width="120" @change="change" bg-color="#f9f9f9" style="padding: 20rpx 0;"></u-tabs>
			</view>
			<view class="page-content">
				<scroll-view class="scroll-view" scroll-y>
					<view v-for="(item,index) in refundList" :key="index">
						<!-- 订单管理基础模板 -->
						<view class="order-manage-card">
							<view class="top" @click='toRefundDeatil(item)'>
								<view class="top-number">
									<text>订单编号： </text><text class="number"> {{item.order_id}}</text>
								</view>
								<view class="top-state">
									<text>{{item.pro_states == 1 ? '未收货' : '已收货'}}</text>
								</view>
							</view>
							<view class="content" @click='toRefundDeatil(item)'>
								<goods-info :data="item.good_item"></goods-info>
								<view class="content-info">
									<text class="left">退款原因</text>
									<text class="right">{{item.reason}}</text>
								</view>
								<view class="content-info">
									<text class="left">退款金额</text>
									<text class="right">￥{{item.refund_price}}</text>
								</view>
							</view>
							<view class="bottom">
								<view class="bottom-left">
									<text>{{$u.timeFormat(item.apply_time, 'yyyy-mm-dd')}}</text>
								</view>
								<view class="bottom-right" v-if="item.apply_status == 0">
									<button type="default" plain="true" @click="operate(item.id,1)">拒绝退货</button>
									<button type="default" plain="true" style="background-color: #2ba4f7; color: #fff;" @click="operate(item.id,2)">同意退货</button>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
				<tui-no-data imgUrl="https://sbb-sbb.oss-cn-shenzhen.aliyuncs.com/Open_source_project/mine/empty_bg.png" v-if="noData1">暂无数据</tui-no-data>
				<view class="bootom-box">
					<load-more :visible="loadMore "></load-more>
					<om-nomore :visible="noMoreFlag && !noData1" bgcolor="#f9f9f9"></om-nomore>
				</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				tabList: [
					{
						name: '待审核'
					},{
						name: '审核成功'
					},{
						name: '审核失败'
					},{
						name: '全部'
					}
				],
				refundList:[],
				current: 0,           // 指定第一页为初始页面
				currentPage: 1,       //分页
				total: 0,             //数据总数
				loadMore: false,      //数据加载中
				noMoreFlag: false,     //没有更多数据了
				noData1: false,       //没有数据
				applyStatus: '',      //退款订单当前状态
				isVerify:false,       //避免重复提交
			};
		},
		onShow() {
			this.clear();
			this.getRefund()
		},
		methods: {
			//顶部section改变
			change(index) {
				this.current = index;
				this.clear();
				this.getRefund()
			},
			//获得数据
			getRefund(){
				this.loadMore = true;
				this.applyStatus = this.current == 3 ?  '' : this.current;
				this.$http.post('/api/auth/order/refList',{businId: this.$store.state.userInfo.id,applyStatus:this.applyStatus,currentPage:this.currentPage}).then(res => {
					this.loadMore = false;
					this.total = res.data.total;
					if(this.total == 0) return this.noData1 = true;
					
					let bbb = res.data.rows;
					bbb.forEach(item => {
						item.good_item = JSON.parse(item.good_item);
						item.upload_pri = JSON.parse(item.upload_pri)
					});
					this.refundList = this.refundList.concat(bbb)
				})
			},
			//跳转退款详情
			toRefundDeatil(item){
				this.$u.route('pages/home/order-manage/refund-detail/refund-detail');
				//先跳转页面，在通过嵌套$emit传数据
				uni.$once('need',() => {
					uni.$emit('detail',{
						item: item
					})
				})
			},
			//审核，1拒绝退款，2同意退款
			operate(id,btn){
				if(this.isVerify) return this.$tip.toast('手速太快，悠着点~');
				this.isVerify = true;
				
				let url = btn == 1 ? '/api/auth/order/auditThroughPlus' : '/api/order/pay/agreeRefund';
				this.$http.post(url,id).then(res => {
					setTimeout(() => {
						this.isVerify = false;
						this.clear();
						this.getRefund()
					},1000);
					this.$tip.toast('操作成功')
				})
			},
			//切换tab，重新请求，需清空原有数据
			clear(){
				this.refundList = [];
				this.noData1 = false;
				this.noMoreFlag = false;
				this.currentPage = 1;
				this.total = 0
			},
		},
		onReachBottom(){
			if(this.total == this.refundList.length) return this.noMoreFlag = true;
			this.currentPage++;
			this.getRefund()
		}
	};
</script>


<style lang="scss" scoped>
.tab-page{
	.tab{
		z-index: 2;
		position: fixed;
		width: 100vw;
	}
	.page-content{
		padding-top: 80rpx;
		height: calc(100% - 184rpx);
		.scroll-view{
			height: 100%;
		}
	}
}

.order-manage-card{
	margin: 30rpx 20rpx;
	padding: 30rpx 20rpx;
	height: 500rpx;
	border-radius: 20rpx;
	background-color: #fff;
	.top{
		display: flex;
		justify-content: space-between;
		padding: 10rpx 0;
		font-size: 13px;
		.top-number{
			.number{
				margin-left: 10rpx;
				font-size: 15px;
				font-weight: 700;
			}
		}
		.top-state{
			color:#2ba4f7;
		}
		
	}
	.content{
		margin: 30rpx 0;
		.content-info{
			display: flex;
			flex-wrap: nowrap;
			margin: 14rpx 0;
			font-size: 13px;
			line-height: 40rpx;
			.left{
				display: inline-block;
				width: 160rpx;
				color:#9e9e9e;
				font-weight: 400;
			}
			.right{
				max-width: 500rpx;
			}
		}
		
	}
	.bottom{
		display: flex;
		align-items: center;
		justify-content: space-between;
		.bottom-left{
			// margin-left: 20rpx;
			color: #bebebe;
		}
		.bottom-right{
			display: flex;
			button{
				margin-left: 20rpx;
				width: 200rpx;
				height: 60rpx;
				font-size: 14px;
				line-height: 60rpx;
				color: #2ba4f7;
				border: none;
				border-radius: 40rpx;
				background-color: #f7f7f7;
			}
		}
	}
}

.bootom-box{
	height: 160rpx;
}
</style>


